<template>
	<view class="report">
		<view class="post-info" v-if="JSON.stringify(post) != '{}'">
			<text>
				{{post.title?post.title:$_filterHtml(post.content)}}
			</text>
		</view>
		<view class="reason-for-reporting-title">请标注举报理由</view>
		<textarea
			placeholder="举报理由"
			placeholder-style="font-size: 28rpx;color: #C0C4CC;"
			maxlength="-1"
			v-model="vModelReasonForReporting"></textarea>
		<view class="button" @click="clickButton">举报</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				pid:"",
				cid:"",
				gid:"",
				type:"",
				post:{},
				vModelReasonForReporting:"",
				reportPost:{},
			}
		},
		onLoad(e) {
			this.pid = e.pid;
			this.gid = e.gid;
			this.type = e.type;
			uni.setNavigationBarTitle({ title: this.type=='post'?'举报帖子':'举报回复' })
			uni.request({
				url:this.$_Config() + "Config.json",
				method:'GET',
				success: (res) => {
					this.reportPost = res.data.reportPost;
					if(this.type == 'post'){
						this.getPost();
					}
				}
			})
		},
		methods: {
			getPost(){
				this.$_Request(
					"GET","/api/v2/post/"+this.pid+"/detail",
					{
						"whitelistKeys":"title,content"
					},
					(res) => {
						this.post = res.data.data.detail;
					}
				)
			},
			// 举报按钮
			clickButton(){
				uni.showLoading();
				this.$_Request(
					"POST","/api/v2/editor/post/quick-publish",
					{
						"postQuotePid":this.pid,
						"postGid":this.reportPost.gid,
						"postTitle":"内容举报",
						"content":this.vModelReasonForReporting
					},
					(res) => {
						uni.hideLoading();
						if(res.data.code == 0){
							uni.showToast({
								title:"举报成功",
								icon:"none",
								duration:500
							});
							setTimeout(()=>{
								uni.navigateBack();
							},500);
						}else{
							uni.showToast({
								title:res.data.message,
								icon:"none",
								duration:1000
							});
						}
					}
				)
			},
		}
	}
</script>

<style lang="scss">
.report{
	.post-info{
		border: 1rpx solid $BianKuangSe;
		background: $BeiJingSe;
		margin: 25rpx;
		margin-bottom: 0;
		padding: 15rpx 20rpx;
		line-height: 42rpx;
		text{
			font-size: 28rpx;
			display: -webkit-box;
			/*!autoprefixer:off*/
			-webkit-box-orient: vertical;
			/*autoprefixer:on*/
			-webkit-line-clamp: 3;
			overflow: hidden;
		}
	}
	.reason-for-reporting-title{
		font-weight: bold;
		margin: 25rpx;
		margin-bottom: 0;
		font-size: 28rpx;
		line-height: 28rpx;
	}
	textarea{
		border: 1rpx solid $BianKuangSe;
		margin: 25rpx;
		background: $BeiJingSe;
		font-size: 28rpx;
		overflow: hidden;
		padding: 15rpx 20rpx;
		width:calc(100% - 2rpx - 40rpx - 50rpx);
		height: 200rpx;
	}
	.button{
		background: $LanSe;
		font-size: 28rpx;
		line-height: 28rpx;
		color: #FFF;
		width: 300rpx;
		height: 80rpx;
		margin: auto;
		display: flex;
		align-items: center;
		justify-content: center;
		border-radius: 100rpx;
	}
}
</style>
